package com.itheima.Arrays.递归;

/**
 * @Author 王加鑫
 * @Date 2021/5/10 18:17
 * @Version 1.0
 */
public class Test1 {

    public static void main(String[] args) {
        System.out.println(getSum(100));
        System.out.println(noDeath(20));
        System.out.println(noDeath1(20));

    }

    public static int getSum(int i){
        if(i == 1){
            return 1;
        }else {
            return i + getSum(i-1);
        }
    }

    /*
    1   1
    2   1
    3   2
    4   3
    5   5
    6   8
    7   13
     */
    public static int noDeath(int month){
        if(month ==1 || month == 2){
            return 1;
        }else {
            return noDeath(month-1) + noDeath(month-2);
        }
    }


    public static int noDeath1(int month){
        int[] arr = new int[month];
        arr[0] = 1;
        arr[1] = 1;
        for (int i = 2; i < arr.length; i++) {
            arr[i] = arr[i-1] + arr[i-2];
        }
        return arr[month-1];
    }

}
